package com.clz.servlet;

import com.clz.servise.Impl.VoteSercieImp;
import com.clz.servise.VoteService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/Vote")
public class VoteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String a = req.getParameter("items");
        VoteService voteService = new VoteSercieImp();
        boolean boo = voteService.Vote(Integer.parseInt(a));
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out =resp.getWriter();
        if (boo) {
            out.println("<script>alert(\"恭喜你，投票成功！\")</script>");
        }

    }
}
